package com.qfedu.yanglao20admin.plancase.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qfedu.yanglao20.common.CommonResult;
import com.qfedu.yanglao20.common.annotation.LogInfo;
import com.qfedu.yanglao20.entity.plancase.CaseAffiliation;
import com.qfedu.yanglao20admin.plancase.param.CaseAffiliationParam;
import com.qfedu.yanglao20admin.plancase.service.CaseAffiliationService;
import com.qfedu.yanglao20admin.plancase.vo.CaseAffiliationVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author yujie
 * @data 2023/4/23 12:50
 */
@Api(tags = "预案归属")
@RestController
@RequestMapping("/affiliation")
public class CaseAffiliationController {

    @Resource
    private CaseAffiliationService caseAffiliationService;


    @LogInfo
    @ApiOperation(value = "分页展示预案归属信息", notes = "分页展示预案归属信息")
    @GetMapping("/page")
    public CommonResult<CaseAffiliation> page(CaseAffiliationParam param) {
        Page<CaseAffiliationVO> caseAffiliationVOPage =
                caseAffiliationService.pageCaseAffiliation(param);
        return CommonResult.success(caseAffiliationVOPage);
    }

    @LogInfo
    @ApiOperation(value = "根据id删除预案归属信息", notes = "根据id删除预案归属信息")
    @GetMapping("/delete")
    public CommonResult<CaseAffiliation> deleteCaseAffiliation(@RequestParam @ApiParam("预案归属id") Integer id) {
        caseAffiliationService.deleteById(id);
        return CommonResult.success();
    }

    @LogInfo
    @ApiOperation(value = "添加预案归属信息", notes = "添加预案归属信息")
    @PostMapping("/add")
    public CommonResult<CaseAffiliation> addCaseAffiliation(CaseAffiliation caseAffiliation) {
        caseAffiliationService.insertCaseAffiliation(caseAffiliation);
        return CommonResult.success();
    }

    @LogInfo
    @ApiOperation(value = "根据id查询预案归属信息", notes = "根据id查询预案归属信息")
    @GetMapping("/query")
    public CommonResult<CaseAffiliation> queryCaseAffiliation(@RequestParam @ApiParam("预案归属id") Integer id) {
        CaseAffiliation caseAffiliation = caseAffiliationService.selectById(id);
        return CommonResult.success(caseAffiliation);
    }

    @LogInfo
    @ApiOperation(value = "修改预案归属信息", notes = "修改预案归属信息")
    @PostMapping("/update")
    public CommonResult<CaseAffiliation> updateCaseAffiliation(CaseAffiliation caseAffiliation) {
        caseAffiliationService.updateCaseAffiliation(caseAffiliation);
        return CommonResult.success();
    }

    @LogInfo
    @ApiOperation(value = "查询所有预案归属信息", notes = "查询所有预案归属信息")
    @GetMapping("/all")
    public CommonResult<CaseAffiliation> queryAllCaseAffiliation() {
        List<CaseAffiliation> caseAffiliations = caseAffiliationService.selectAll();
        return CommonResult.success(caseAffiliations);
    }
}
